home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group99a.txt
/
000144_icon-group-sender _Wed Jun 23 09:06:16 1999.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id JAA10769
for icon-group-addresses; Wed, 23 Jun 1999 09:05:33 -0700 (MST)
Message-Id: <199906231605.JAA10769@baskerville.CS.Arizona.EDU>
Date: Wed, 23 Jun 1999 12:31:37 +1200 (NZST)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
To: dgamey@ca.ibm.com, oikonomou@att.com
Subject: Re: Assertions in Icon
Cc: icon-group@optima.CS.Arizona.EDU
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
>Does anyone have a suggestion about how to implement a procedure "assert",
>which, when called with an expression "e" as argument, implements
>
> e | stop("Assertion on line ", &line, " failed!")
>
>Here &line should be the line on which assert(e) appears.
The obvious answer is "do it the way C does; use a preprocessor".
In what follows, I'm going to use M4, because
- it's the traditional UNIX macro processor
- there are two free versions: GNU M4 and pdm4
- I know it fairly well.
Method 1.
define(assert, `real_assert((`$1'), &line)')
where the real_assert procedure is plain Icon code.
Method 2.
define(assert, `((`$1') | stop("Assertion on line ", &line, " failed!"))')
where now everything is in the macro.
That's the quick and easy way. A better way, long term, would be for
someone to patch the Icon translator to support `assert'. It's *FAR*
too powerful a debugging tool to leave out of the language much longer.